package linker

import (
	"log"
	"net"
	"test/protocol"
	"time"
)

func StartClient(pro protocol.Protocol, host string, rtu int16, status chan int) {
	for {
		time.Sleep(time.Second * 5)
		localAddress, _ := net.ResolveTCPAddr("tcp", host)
		conn, err := net.DialTCP("tcp", nil, localAddress)
		if err != nil {
			log.Println(err)
			continue
		}
		defer func() {
			status <- LinkerQuitTcpConn
			conn.Close()
			if e := recover(); e != nil {
				log.Printf("Panicking %s\r\n", e)
			}
		}()

		r := handlerclient(conn, pro, rtu)
		if r == LinkerQuit {
			continue
		}
	}
}
